Skip to content

Introduce KEP 5975: Declarative API Definitions#5974

Open
jpbetz wants to merge 5 commits intokubernetes:masterfrom
jpbetz:declarative-apis
Open

Introduce KEP 5975: Declarative API Definitions#5974
jpbetz wants to merge 5 commits intokubernetes:masterfrom
jpbetz:declarative-apis

Conversation

@jpbetz
Copy link
Copy Markdown
Contributor

@jpbetz jpbetz commented Mar 23, 2026

@k8s-ci-robot k8s-ci-robot added kind/kep Categorizes KEP tracking issues and PRs modifying the KEP directory sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 23, 2026
@jpbetz jpbetz changed the title Draft KEP proposal: Declarative API definitions Introduce KEP 5975: Declarative API Definitions Mar 23, 2026
@jpbetz jpbetz force-pushed the declarative-apis branch from 5e16441 to 194333b Compare March 23, 2026 18:57
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jpbetz

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jpbetz
Copy link
Copy Markdown
Contributor Author

jpbetz commented Mar 23, 2026

@thockin @deads2k @liggitt Looking for early feedback. If there is support I'd like to merge early and work on this in the off cycle.

Comment on lines +155 to +156
without knowing their concrete types. Rather than relying on reflection, we would like to
introduce two interfaces:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not fully convinced this is how I'd like to generically implement wiping. One alternative is reflection.

@jpbetz jpbetz force-pushed the declarative-apis branch from 997fd43 to e2cdb54 Compare March 23, 2026 19:15
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Mar 23, 2026
@jpbetz jpbetz force-pushed the declarative-apis branch 2 times, most recently from 6649b90 to 5151b1a Compare March 23, 2026 21:26
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 23, 2026
@jpbetz jpbetz force-pushed the declarative-apis branch 4 times, most recently from 99bd9c1 to f4fe0c7 Compare March 25, 2026 18:58
@jpbetz jpbetz force-pushed the declarative-apis branch from f4fe0c7 to 1245718 Compare March 25, 2026 20:00
@jpbetz jpbetz mentioned this pull request Apr 2, 2026
5 tasks
@jpbetz
Copy link
Copy Markdown
Contributor Author

jpbetz commented Apr 21, 2026

Note to self: Tests that verify DeepCopy, Conversion, and all other generators are run for each type would eliminate another aspect of manual API Review.

@jpbetz jpbetz force-pushed the declarative-apis branch from 0160c85 to 37d9d16 Compare April 27, 2026 22:01
Comment on lines +163 to +198
### Code generation

Rather than independently enable individual code generators with tags, code generation will
be on-by-default for all API definitions in code where declaration files exist.

`GroupVersion` will be placed in external API definition directories, For example:

`staging/src/k8s.io/api/admission/v1/groupversion.yaml`:

```yaml
apiVersion: apidefinitions.k8s.io/v1alpha1
kind: GroupVersion

group: admission.k8s.io
version: v1
modelName: io.k8s.admission
```

This file defines all common properties of a group and it's presence indicates that
all external code generation, such as typed clients and openapi, should be run for this
group of resources.

`GroupVersionRegistration` will be placed in internal API registration directories, For example:

`pkg/apis/admission/v1/registration.yaml`:

```yaml
apiVersion: apidefinitions.k8s.io/v1alpha1
kind: GroupVersionRegistration

group: admission.k8s.io
version: v1
externalTypes: k8s.io/api/admission/v1
peers:
- k8s.io/kubernetes/pkg/apis/admission
```
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liggitt @thockin To simplify code generator management, I'm looking a way of enabling all code-generators by-default for in-tree APIs.

Initially I just tried adding a enforcement check that complained if an API author doesn't add all the +k8s:deepcopy-gen=true type tags, but @thockin mentioned look into driving the generators of small declarations. So I'm trying it out. This section shows what it would roughly look like.

Questions:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with a file that describes which generator to run and how. Sounds similar to https://github.com/openshift/api/blob/master/example/.codegen.yaml in OpenShift. Some issues we've had:

  1. opt-in or opt-out or both. As the generators grow, it is sort of like admission. We have new items that contain default-on or default-off preferences and each API can have an "explicit off" or "explicit on" preference.
  2. Configuring at group level, across all versions made for fewer files, but more painful changes when we needed to start bringing new generators online.
  3. This became a natural place for validation and linting exceptions too. Not sure about your plan for growth there.

@JoelSpeed migrated us to the file and has been more hands on dealing with it recently.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea we'd like to start with is:

  • Here's a file that says everything code generators need to know about the API declaring files in in this directory
  • When present, the generators run in a way that conforms to our API guidelines

I've got a PoC that shows this working against all in-tree APIs correctly and removes the need for a bunch of generator enablement tags in each doc.go file.

I do expect this to grow. I don't want it to accumulate validation/lint exceptions here.

For ecosystem adoption, I think it's fine to use outside of k/k. I would like it to focus on opinions we have for in-tree APIs. So if 3rd parties use it, they need to buy-in to our opinions.

@jpbetz
Copy link
Copy Markdown
Contributor Author

jpbetz commented Apr 30, 2026

@alvaroaleman does kubebuilder depend on any of the +k8s:deepcopy=package or other generator enablement tags in doc.go?

My intuition is that this propose would not impact kubebuilder, but want to double check.

@jpbetz jpbetz force-pushed the declarative-apis branch from e955197 to f0ed9d8 Compare April 30, 2026 16:39

- **Main strategy**: clears status on create (`obj.Status = TypeStatus{}`),
and clears status changes on update (`new.Status = old.Status`).
- **Status substrategy**: clears spec, labels, and annotations changes
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we phrase this to clear all new fields as they're added unless we take active effort? I'd like that so we're forced to think about it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point. I'll rephrase this.


This requires [Spec/Status accessor interfaces](#specstatus-accessor-interfaces).

### Feature-Gate Field Dropping
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably the most valuable part for me personally.


**Hooks:**

| Hook | Purpose |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no Hook for PrepareForCreate or PrepareForUpdate?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll call it out.

@deads2k
Copy link
Copy Markdown
Contributor

deads2k commented May 1, 2026

A few questions and comments. I like the idea.

@alvaroaleman
Copy link
Copy Markdown
Member

@alvaroaleman does kubebuilder depend on any of the +k8s:deepcopy=package or other generator enablement tags in doc.go?

It depends on what you mean by "depends on", it does interpret them but that probably doesn't matter for in-tree resources as I don't think there is a good reason to use it to generate DeepCopies for in-tree resources: https://github.com/kubernetes-sigs/controller-tools/blob/e17f046d11b6e9e508d11abc37891b66831aefa4/pkg/deepcopy/gen.go#L45-L47

@jpbetz
Copy link
Copy Markdown
Contributor Author

jpbetz commented May 1, 2026

@alvaroaleman does kubebuilder depend on any of the +k8s:deepcopy=package or other generator enablement tags in doc.go?

It depends on what you mean by "depends on", it does interpret them but that probably doesn't matter for in-tree resources as I don't think there is a good reason to use it to generate DeepCopies for in-tree resources: kubernetes-sigs/controller-tools@e17f046/pkg/deepcopy/gen.go#L45-L47

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/kep Categorizes KEP tracking issues and PRs modifying the KEP directory sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants